package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Client;
import cn.wolfcode.crm.query.ClientQueryObject;
import cn.wolfcode.crm.service.IClientService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: crm
 * @description:
 * @author: Mr.chen
 * @create: 2018-07-07 22:06
 **/
@Controller
@RequestMapping("potentialclient")
public class PotentialClientController {
    @Autowired
    private IClientService service;
    @RequestMapping("")
    @PermissionName("潜在客户管理主页")
    @RequiresPermissions("potentialclient:index")
    public String index() {
        return "potentialclient/list";
    }

    @ResponseBody
    @RequestMapping("list")
    @PermissionName("潜在客户管理数据")
    @RequiresPermissions("potentialclient:list")
    public PageResult list(ClientQueryObject qo) {
        qo.setState1(1);
        PageResult result = service.query(qo);
        return result;
    }

    @RequestMapping("save")
    @ResponseBody
    @RequiresPermissions("potentialclient:save")
    @PermissionName("潜在客户管理保存")
    public JsonResult save(Client entity) {
        JsonResult result = new JsonResult();
        try {
            service.save(entity);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }
}
